<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>互助码</title>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./js/codemirror.min.js"></script>
    <script type="text/javascript" src="./js/shell.js"></script>
    <script type="text/javascript" src="./js/sweetalert2.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/codemirror.min.css">
    <link rel="stylesheet" type="text/css" href="./css/twilight.css">
    <link rel="stylesheet" type="text/css" href="./css/dracula.css">
    <link rel="stylesheet" type="text/css" href="./css/main.css">
</head>

<body>
<div class="container">
    <div class="diffs">
        <nav>
            <ul>
                <li><a href="./home">参数配置</a></li>
                <li><a href="./crontab">定时设定</a></li>
                <li><a href="./diff">对比工具</a></li>
                <li class="active"><a href="./shareCode">互助码</a></li>
                <li><a href="./diy">自定义脚本</a></li>
                <li><a href="./log">日志查询</a></li>
                <li><a href="./changepwd">修改密码</a></li>
                <li><a href="./logout">退出</a></li>
            </ul>
        </nav>
        <header>
            <h1>互助码在线查看</h1>
            <button id="refresh" title="手动刷新">手动刷新</button>
            <br/>
            <p>此处显示的互助码来源于 log/export_sharecodes 目录中的输出日志</p>
            <br/><br/>
        </header>
        <div class="wrapper">
            <textarea id="code" name="code" readonly="readonly"></textarea>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
            lineNumbers: true,
            lineWrapping: true,
            styleActiveLine: true,
            matchBrackets: true,
            readOnly: true,
            mode: 'text',
            theme: 'dracula'
        });
        let timeStamp = (new Date()).getTime()
        $.get("./api/config/shareCode?t="+timeStamp, function (data) {
            editor.setValue(data);
        });

        $('#refresh').click(function () {
            document.getElementById("refresh").disabled=true;
            let timeStamp = (new Date()).getTime()
            $.post('./api/sharecodes?t='+timeStamp, {}, function (data) {
                let icon = (data.err == 0) ? "success" : "error"
                Swal.fire({
                    title:data.title,
                    text: data.msg,
                    icon: icon
                }).then((result) => {
                    window.location.reload(true);
                })
            });
        });
    });

</script>

</body>

</html>
